home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group9]VCL Source Standard / IvPSDlg.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-12  |  17.2 KB  |  612 lines

  1. unit IvPSDlg;
  2.  
  3. {$I IVMULTI.INC}
  4.  
  5. interface
  6.  
  7. uses
  8.   Windows, Classes, Controls, Graphics, Dialogs, CommDlg,
  9.   IvDictio;
  10.  
  11. type
  12.   TIvPageSetupOption = (ivpoDefaultMinMargins, ivpoDisableMargins,
  13.     ivpoDisableOrientation, ivpoDisablePagePainting, ivpoDisablePaper,
  14.     ivpoDisablePrinter, ivpoNoWarning, ivpoShowHelp);
  15.   TIvPageSetupOptions = set of TIvPageSetupOption;
  16.   TIvPSPaperType = (ivptPaper, ivptEnvelope);
  17.   TIvPSPaperOrientation = (ivpoPortrait, ivpoLandscape);
  18.   TIvPSPrinterType = (ivptDotMatrix, ivptHPPCL);
  19.   TIvPSPaintWhat = (ivpwFullPage, ivpwMinimumMargins, ivpwMargins,
  20.     ivpwGreekText, ivpwEnvStamp, ivpwYAFullPage);
  21.  
  22.   TIvPSMeasurements = (ivpmDefault, ivpmMillimeters, ivpmInches);
  23.   
  24.   TIvPSPrinterEvent = procedure(sender: TObject; wnd: HWnd) of object;
  25.  
  26.   PIvPageSetupDlg = ^TIvPageSetupDlg;
  27.   TIvPageSetupDlg = TPageSetupDlg;
  28.  
  29.   TIvPSInitPaintPageEvent = function(
  30.     sender: TObject;
  31.     paperSize: Integer;
  32.     paperType: TIvPSPaperType;
  33.     paperOrientation: TIvPSPaperOrientation;
  34.     printerType: TIvPSPrinterType;
  35.     setupData: PIvPageSetupDlg): Boolean of object;
  36.  
  37.   TIvPSPaintPageEvent = function(
  38.     sender: TObject;
  39.     paintWhat: TIvPSPaintWhat;
  40.     canvas: TCanvas;
  41.     rect: TRect): Boolean of object;
  42.  
  43.   TIvPageSetupDialog = class(TCommonDialog)
  44.   private
  45.     FOptions: TIvPageSetupOptions;
  46.     FPaperSize: TPoint;
  47.     FMinimumMargins: TRect;
  48.     FMargins: TRect;
  49.     FMeasurements: TIvPSMeasurements;
  50.     FParent: TWinControl;
  51.     FPositions: TIvDialogPositions;
  52.     FDictionary: TIvDictionary;
  53.     FDictionaryName: String;
  54.     FOnPrinter: TIvPSPrinterEvent;
  55.     FOnInitPaintPage: TIvPSInitPaintPageEvent;
  56.     FOnPaintPage: TIvPSPaintPageEvent;
  57.  
  58.     procedure SetDictionary(value: TIvDictionary);
  59.     procedure SetDictionaryName(const value: String);
  60.     procedure InitDictionary;
  61.     function GetParentWnd: HWnd;
  62.  
  63.     function DoPrinter(wnd: HWnd): Boolean;
  64.     function DoExecute(func: Pointer): Boolean;
  65.  
  66.   protected
  67.     function Printer(wnd: HWnd): Boolean; virtual;
  68.     function TaskModalDialog(dialogFunc: Pointer; var dialogData): Bool; override;
  69.  
  70.   public
  71.     constructor Create(owner: TComponent); override;
  72.  
  73.     function Execute: Boolean; override;
  74.  
  75.     property PaperSize: TPoint read FPaperSize write FPaperSize;
  76.     property MinimumMargins: TRect read FMinimumMargins write FMinimumMargins;
  77.     property Margins: TRect read FMargins write FMargins;
  78.     property Dictionary: TIvDictionary read FDictionary write SetDictionary;
  79.  
  80.   published
  81.     property Options: TIvPageSetupOptions read FOptions write FOptions default [ivpoDefaultMinMargins, ivpoShowHelp];
  82.     property Measurements: TIvPSMeasurements read FMeasurements write FMeasurements default ivpmDefault;
  83.     property Positions: TIvDialogPositions read FPositions write FPositions default [ivdpParent, ivdpCenter];
  84.     property Parent: TWinControl read FParent write FParent;
  85.     property DictionaryName: String read FDictionaryName write SetDictionaryName;
  86.     property OnPrinter: TIvPSPrinterEvent read FOnPrinter write FOnPrinter;
  87.     property OnInitPaintPage: TIvPSInitPaintPageEvent read FOnInitPaintPage write FOnInitPaintPage;
  88.     property OnPaintPage: TIvPSPaintPageEvent read FOnPaintPage write FOnPaintPage;
  89.   end;
  90.  
  91. function IvPageSetupDlg(
  92.   var ps: TPageSetupDlg;
  93.   dictionary: TIvDictionary;
  94.   center: Boolean;
  95.   parent: HWnd): Bool; stdcall;
  96.  
  97. procedure Register;
  98.  
  99. implementation
  100.  
  101. uses
  102.   SysUtils, Messages, Forms, Printers;
  103.  
  104. var
  105.   FCreationControl: TIvPageSetupDialog = nil;
  106.   FHookCtl3D: Boolean;
  107.   FPageSetupDialog: TIvPageSetupDialog;
  108.   FCenter: Boolean;
  109.   FParent: HWnd;
  110.   FPS: TPageSetupDlg;
  111.   FHookProc: TFarProc;
  112.   FCommonDictionary: TIvDictionary;
  113.  
  114. procedure CenterWindow(wnd: HWnd);
  115. var
  116.   rect, parentRect: TRect;
  117. begin
  118.   GetWindowRect(wnd, rect);
  119.   if FParent = 0 then
  120.   begin
  121.     SetWindowPos(
  122.       wnd,
  123.       0,
  124.       (GetSystemMetrics(SM_CXSCREEN) - (rect.Right - rect.Left)) div 2,
  125.       (GetSystemMetrics(SM_CYSCREEN) - (rect.Bottom - rect.Top)) div 2,
  126.       0,
  127.       0,
  128.       SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
  129.   end
  130.   else
  131.   begin
  132.     GetWindowRect(FParent, parentRect);
  133.     SetWindowPos(
  134.       wnd,
  135.       0,
  136.       parentRect.Left + (parentRect.Right - parentRect.Left - (rect.Right - rect.Left)) div 2,
  137.       parentRect.Top + (parentRect.Bottom - parentRect.Top - (rect.Bottom - rect.Top)) div 2,
  138.       0,
  139.       0,
  140.       SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
  141.   end;
  142. end;
  143.  
  144. function TranslatePageSetupDialog(wnd: HWnd; reserved: Integer): Bool; stdcall;
  145. begin
  146.   Result := True;
  147.  
  148.   { Translates the window text }
  149.  
  150.   case GetWindowLong(wnd, GWL_ID) of
  151.     0: FCommonDictionary.TranslateWindow(wnd, 'Page Setup', False);
  152.  
  153.     1: FCommonDictionary.TranslateWindow(wnd, 'OK', False);
  154.     2: FCommonDictionary.TranslateWindow(wnd, 'Cancel', False);
  155.     1026: FCommonDictionary.TranslateWindow(wnd, '&Printer...', False);
  156.  
  157.     1073: FCommonDictionary.TranslateWindow(wnd, 'Paper', False);
  158.     1089: FCommonDictionary.TranslateWindow(wnd, 'Si&ze:', True);
  159.     1090: FCommonDictionary.TranslateWindow(wnd, '&Source:', True);
  160.  
  161.     1072: FCommonDictionary.TranslateWindow(wnd, 'Orientation', False);
  162.     1056: FCommonDictionary.TranslateWindow(wnd, 'P&ortrait', True);
  163.     1057: FCommonDictionary.TranslateWindow(wnd, 'L&andscape', True);
  164.  
  165.     1075:
  166.       if (FPS.Flags and PSD_INHUNDREDTHSOFMILLIMETERS) <> 0 then
  167.         FCommonDictionary.TranslateWindow(wnd, 'Margins (millimeters)', False)
  168.       else
  169.         FCommonDictionary.TranslateWindow(wnd, 'Margins (inches)', False);
  170.  
  171.     1102: FCommonDictionary.TranslateWindow(wnd, '&Left:', True);
  172.     1103: FCommonDictionary.TranslateWindow(wnd, '&Right:', True);
  173.     1104: FCommonDictionary.TranslateWindow(wnd, '&Top:', True);
  174.     1105: FCommonDictionary.TranslateWindow(wnd, '&Bottom:', True);
  175.   end;
  176.  
  177.   { Translates the child controls }
  178.  
  179.   EnumChildWindows(wnd, @TranslatePageSetupDialog, 0);
  180. end;
  181.  
  182. function IvPageSetupHook(wnd: HWnd; msg: UINT; wParam: WPARAM; lParam: LPARAM):
  183. {$IFDEF IVBIDI}
  184.   UINT;
  185. {$ELSE}
  186.   Integer;
  187. {$ENDIF}
  188.   stdcall;
  189. begin
  190.   Result := 0;
  191.   case Msg of
  192.     WM_INITDIALOG:
  193.       if FCenter then
  194.         CenterWindow(wnd);
  195.  
  196.     WM_ACTIVATE:
  197.       if (LOWORD(wParam) = WA_ACTIVE) and (FCommonDictionary <> nil) then
  198.         TranslatePageSetupDialog(wnd, 0);
  199.   end;
  200.  
  201.   if Assigned(FHookProc) then
  202.     Result := CallWindowProc(FHookProc, wnd, msg, wParam, lParam);
  203. end;
  204.  
  205. function IvPageSetupDlg(
  206.   var ps: TPageSetupDlg;
  207.   dictionary: TIvDictionary;
  208.   center: Boolean;
  209.   parent: HWnd): Bool;
  210. begin
  211.   FCommonDictionary := dictionary;
  212.   FCenter := center;
  213.   Fparent := parent;
  214.   FPS := ps;
  215.   ps.flags := ps.flags or PSD_ENABLEPAGESETUPHOOK;
  216.   if Assigned(ps.lpfnPageSetupHook) then
  217.     FHookProc := @ps.lpfnPageSetupHook
  218.   else
  219.     FHookProc := nil;
  220.   ps.lpfnPageSetupHook := IvPageSetupHook;
  221.   Result := PageSetupDlg(ps);
  222. end;
  223.  
  224. procedure GetPrinter(var deviceMode, deviceNames: THandle);
  225. var
  226.   Device, Driver, Port: array[0..79] of Char;
  227.   DevNames: PDevNames;
  228.   Offset: PChar;
  229. begin
  230.   Printer.GetPrinter(Device, Driver, Port, DeviceMode);
  231.   if DeviceMode <> 0 then
  232.   begin
  233.     DeviceNames := GlobalAlloc(GHND, SizeOf(TDevNames) +
  234.      StrLen(Device) + StrLen(Driver) + StrLen(Port) + 3);
  235.     DevNames := PDevNames(GlobalLock(DeviceNames));
  236.     try
  237.       Offset := PChar(DevNames) + SizeOf(TDevnames);
  238.       with DevNames^ do
  239.       begin
  240.         wDriverOffset := Longint(Offset) - Longint(DevNames);
  241.         Offset := StrECopy(Offset, Driver) + 1;
  242.         wDeviceOffset := Longint(Offset) - Longint(DevNames);
  243.         Offset := StrECopy(Offset, Device) + 1;
  244.         wOutputOffset := Longint(Offset) - Longint(DevNames);;
  245.         StrCopy(Offset, Port);
  246.       end;
  247.     finally
  248.       GlobalUnlock(DeviceNames);
  249.     end;
  250.   end;
  251. end;
  252.  
  253. procedure SetPrinter(DeviceMode, DeviceNames: THandle);
  254. var
  255.   DevNames: PDevNames;
  256. begin
  257.   DevNames := PDevNames(GlobalLock(DeviceNames));
  258.   try
  259.     with DevNames^ do
  260.       Printer.SetPrinter(PChar(DevNames) + wDeviceOffset,
  261.         PChar(DevNames) + wDriverOffset,
  262.         PChar(DevNames) + wOutputOffset, DeviceMode);
  263.   finally
  264.     GlobalUnlock(DeviceNames);
  265.     GlobalFree(DeviceNames);
  266.   end;
  267. end;
  268.  
  269. function CopyData(Handle: THandle): THandle;
  270. var
  271.   Src, Dest: PChar;
  272.   Size: Integer;
  273. begin
  274.   if Handle <> 0 then
  275.   begin
  276.     Size := GlobalSize(Handle);
  277.     Result := GlobalAlloc(GHND, Size);
  278.     if Result <> 0 then
  279.       try
  280.         Src := GlobalLock(Handle);
  281.         Dest := GlobalLock(Result);
  282.         if (Src <> nil) and (Dest <> nil) then
  283.           Move(Src^, Dest^, Size);
  284.       finally
  285.         GlobalUnlock(Handle);
  286.         GlobalUnlock(Result);
  287.       end
  288.   end
  289.   else
  290.     Result := 0;
  291. end;
  292.  
  293. function IvPageSetupDialogHook(wnd: HWnd; msg: UINT; wParam: WPARAM; lParam: LPARAM):
  294. {$IFDEF IVBIDI}
  295.   UINT;
  296. {$ELSE}
  297.   Integer;
  298. {$ENDIF}
  299.   stdcall;
  300. const
  301.   PAGE_PAINT_WHAT_C: array[WM_PSD_FULLPAGERECT..WM_PSD_YAFULLPAGERECT] of TIvPSPaintWhat = (
  302.     ivpwFullPage, ivpwMinimumMargins, ivpwMargins,
  303.     ivpwGreekText, ivpwEnvStamp, ivpwYAFullPage);
  304.   PRINTER_MASK_C = $00000002;
  305.   ORIENT_MASK_C  = $00000004;
  306.   PAPER_MASK_C   = $00000008;
  307.   IDPRINTERBTN_C = $0402;
  308. var
  309.   paperData: Word;
  310.   paper: TIvPSPaperType;
  311.   orient: TIvPSPaperOrientation;
  312.   printer: TIvPSPrinterType;
  313.   paintRect: TRect;
  314.   paintCanvas: TCanvas;
  315. begin
  316.   Result := 0;
  317.   case msg of
  318.     WM_INITDIALOG:
  319.       begin
  320.         if FHookCtl3D then
  321.         begin
  322.           Subclass3DDlg(Wnd, CTL3D_ALL);
  323.           SetAutoSubClass(True);
  324.         end;
  325.         Result := 1;
  326.       end;
  327.  
  328.     WM_DESTROY:
  329.       if FHookCtl3D then
  330.         SetAutoSubClass(False);
  331.  
  332.     WM_COMMAND:
  333.       if (LongRec(WParam).Lo = IDPRINTERBTN_C) and
  334.         (LongRec(WParam).Hi = BN_CLICKED) then
  335.       begin
  336.         Result := Ord(FPageSetupDialog.DoPrinter(Wnd));
  337.       end;
  338.  
  339.     WM_PSD_PAGESETUPDLG:
  340.       // The dialog box is about to draw the sample page
  341.  
  342.       if Assigned(FPageSetupDialog.FOnInitPaintPage) then
  343.       begin
  344.         PaperData := HiWord(WParam);
  345.         if (PaperData and PAPER_MASK_C > 0) then
  346.           Paper := ivptEnvelope
  347.         else
  348.           Paper := ivptPaper;
  349.  
  350.         if (PaperData and ORIENT_MASK_C > 0) then
  351.           Orient := ivpoPortrait
  352.         else
  353.           Orient := ivpoLandscape;
  354.  
  355.         if (PaperData and PAPER_MASK_C > 0) then
  356.           Printer := ivptHPPCL
  357.         else
  358.           Printer := ivptDotMatrix;
  359.  
  360.         Result := Ord(
  361.           FPageSetupDialog.FOnInitPaintPage(
  362.             FPageSetupDialog,
  363.             LoWord(WParam),
  364.             Paper,
  365.             Orient,
  366.             Printer,
  367.             PIvPageSetupDlg(LParam)));
  368.       end;
  369.  
  370.     WM_PSD_FULLPAGERECT,
  371.     WM_PSD_MINMARGINRECT,
  372.     WM_PSD_MARGINRECT,
  373.     WM_PSD_GREEKTEXTRECT,
  374.     WM_PSD_ENVSTAMPRECT,
  375.     WM_PSD_YAFULLPAGERECT:
  376.       // The dialog box is about to draw the sample page
  377.  
  378.       if Assigned(FPageSetupDialog.FOnPaintPage) then
  379.       begin
  380.         if LParam <> 0 then
  381.           PaintRect := PRect(LParam)^
  382.         else
  383.           PaintRect := Rect(0,0,0,0);
  384.  
  385.         PaintCanvas := TCanvas.Create;
  386.         PaintCanvas.Handle := HDC(WParam);
  387.         try
  388.           Result := Ord(FPageSetupDialog.FOnPaintPage(
  389.             FPageSetupDialog,
  390.             PAGE_PAINT_WHAT_C[Msg],
  391.             PaintCanvas,
  392.             PaintRect));
  393.         finally
  394.           PaintCanvas.Free;
  395.         end;
  396.       end;
  397.   end;
  398. end;
  399.  
  400. constructor TIvPageSetupDialog.Create(owner: TComponent);
  401. begin
  402.   inherited Create(owner);
  403.   FOptions := [ivpoDefaultMinMargins, ivpoShowHelp];
  404.   FDictionary := nil;
  405.   FPositions := [ivdpParent, ivdpCenter];
  406.   FOnPrinter := nil;
  407.   FOnInitPaintPage := nil;
  408.   FOnPaintPage := nil;
  409.   FPaperSize := Point(0, 0);
  410.   FMinimumMargins := Rect(0, 0, 0, 0);
  411.   FMargins := Rect(2500, 2500, 2500, 2500);
  412.   FMeasurements := ivpmDefault;
  413. end;
  414.  
  415. procedure TIvPageSetupDialog.InitDictionary;
  416. begin
  417.   if FDictionaryName <> '' then
  418.     FDictionary := Dictionaries.FindDictionary(FDictionaryName);
  419.  
  420.   if (FDictionary = nil) and (Dictionaries.Count > 0) then
  421.     FDictionary := Dictionaries[0];
  422. end;
  423.  
  424. procedure TIvPageSetupDialog.SetDictionary(value: TIvDictionary);
  425. begin
  426.   if value <> FDictionary then
  427.   begin
  428.     FDictionary := value;
  429.     if FDictionary <> nil then
  430.       FDictionaryName := FDictionary.DictionaryName;
  431.   end;
  432. end;
  433.  
  434. procedure TIvPageSetupDialog.SetDictionaryName(const value: String);
  435. begin
  436.   if FDictionaryName <> value then
  437.   begin
  438.     Dictionary := Dictionaries.FindDictionary(value);
  439.     FDictionaryName := value;
  440.   end;
  441. end;
  442.  
  443. function TIvPageSetupDialog.GetParentWnd: HWnd;
  444. begin
  445.   if (ivdpParent in FPositions) and (FParent <> nil) then
  446.     Result := FParent.Handle
  447.   else if (ivdpParent in FPositions) and (Owner is TWinControl) then
  448.     Result := TWinControl(Owner).Handle
  449.   else
  450.     Result := Application.Handle;
  451. end;
  452.  
  453. function TIvPageSetupDialog.TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool;
  454. type
  455.   TDialogFunc = function(
  456.     var DialogData;
  457.     dictionary: TIvDictionary;
  458.     center: Boolean;
  459.     parent: HWnd): Bool stdcall;
  460. var
  461.   ActiveWindow: HWnd;
  462.   WindowList: Pointer;
  463. begin
  464.   ActiveWindow := GetActiveWindow;
  465.   WindowList := DisableTaskWindows(0);
  466.   try
  467.     Application.HookMainWindow(MessageHook);
  468.     try
  469.       FCreationControl := Self;
  470.       Result := TDialogFunc(DialogFunc)(DialogData, FDictionary, ivdpCenter in FPositions, GetParentWnd);
  471.       // Avoid FPU control word change in NETRAP.dll, NETAPI32.dll, etc
  472. {$IFDEF IVWIDE}
  473.       Set8087CW(Default8087CW);
  474. {$ENDIF}
  475.     finally
  476.       Application.UnhookMainWindow(MessageHook);
  477.     end;
  478.   finally
  479.     EnableTaskWindows(WindowList);
  480.     SetActiveWindow(ActiveWindow);
  481.   end;
  482. end;
  483.  
  484. function TIvPageSetupDialog.DoExecute(func: pointer): Boolean;
  485. const
  486.   PAGE_SETUP_OPTIONS_C: array[TIvPageSetupOption] of DWord = (
  487.     PSD_DEFAULTMINMARGINS, PSD_DISABLEMARGINS, PSD_DISABLEORIENTATION,
  488.     PSD_DISABLEPAGEPAINTING, PSD_DISABLEPAPER, PSD_DISABLEPRINTER,
  489.     PSD_NOWARNING, PSD_SHOWHELP);
  490. var
  491.   isMetric: Boolean;
  492.   option: TIvPageSetupOption;
  493.   pageSetup: TPageSetupDlg;
  494.   savePageSetupDialog: TIvPageSetupDialog;
  495.   devHandle: THandle;
  496. begin
  497.   FillChar(pageSetup, SizeOf(pageSetup), 0);
  498.   with pageSetup do
  499.   try
  500.     lStructSize := SizeOf(TPageSetupDlg);
  501.  
  502. {$IFDEF IVWIDE}
  503.     hInstance := SysInit.HInstance;
  504. {$ELSE}
  505.     hInstance := System.HInstance;
  506. {$ENDIF}
  507.  
  508.     hwndOwner := Application.Handle;
  509.  
  510.     Flags := PSD_MARGINS;
  511.  
  512.     for Option := Low(Option) to High(Option) do
  513.       if Option in FOptions then
  514.         Flags := Flags or PAGE_SETUP_OPTIONS_C[Option];
  515.  
  516.     rtMinMargin := FMinimumMargins;
  517.     rtMargin := FMargins;
  518.  
  519.     if FMeasurements = ivpmDefault then
  520.     begin
  521.       if Dictionary <> nil then
  522.         isMetric := Dictionary.LocaleData.MeasurementSystem = ivmsMetric
  523.       else
  524.         isMetric := GetLocaleStr(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, '0') = '0';
  525.  
  526.       if isMetric then
  527.         Flags := Flags or PSD_INHUNDREDTHSOFMILLIMETERS
  528.       else
  529.       begin
  530.         Flags := Flags or PSD_INTHOUSANDTHSOFINCHES;
  531.  
  532.         rtMinMargin.Left := Round(rtMinMargin.Left/254)*100;
  533.         rtMinMargin.Right := Round(rtMinMargin.Right/254)*100;
  534.         rtMinMargin.Top := Round(rtMinMargin.Top/254)*100;
  535.         rtMinMargin.Bottom := Round(rtMinMargin.Bottom/254)*100;
  536.  
  537.         rtMargin.Left := Round(rtMargin.Left/254)*100;
  538.         rtMargin.Right := Round(rtMargin.Right/254)*100;
  539.         rtMargin.Top := Round(rtMargin.Top/254)*100;
  540.         rtMargin.Bottom := Round(rtMargin.Bottom/254)*100;
  541.       end;
  542.     end
  543.     else if FMeasurements = ivpmMillimeters then
  544.       Flags := Flags or PSD_INHUNDREDTHSOFMILLIMETERS
  545.     else
  546.       Flags := Flags or PSD_INTHOUSANDTHSOFINCHES;
  547.  
  548.     Flags := Flags or PSD_ENABLEPAGESETUPHOOK or PSD_ENABLEPAGEPAINTHOOK;
  549.     lpfnPageSetupHook := IvPageSetupDialogHook;
  550.     lpfnPagePaintHook := IvPageSetupDialogHook;
  551.  
  552.     GetPrinter(devHandle, hDevNames);
  553.     hDevMode := CopyData(devHandle);
  554.  
  555.     FHookCtl3D := Ctl3D;
  556.     ptPaperSize := FPaperSize;
  557.  
  558.     savePageSetupDialog := FPageSetupDialog;
  559.     FPageSetupDialog := Self;
  560.     Result := TaskModalDialog(Func, pageSetup);
  561.     FPageSetupDialog := savePageSetupDialog;
  562.     if Result then
  563.     begin
  564.       FPaperSize := ptPaperSize;
  565.       FMinimumMargins := rtMinMargin;
  566.       FMargins := rtMargin;
  567.       SetPrinter(hDevMode, hDevNames);
  568.     end
  569.     else
  570.     begin
  571.       if hDevMode <> 0 then
  572.         GlobalFree(hDevMode);
  573.       if hDevNames <> 0 then
  574.         GlobalFree(hDevNames);
  575.     end;
  576.   finally
  577.   end;
  578. end;
  579.  
  580. function TIvPageSetupDialog.Execute: boolean;
  581. begin
  582.   InitDictionary;
  583.   Result := DoExecute(@IvPageSetupDlg);
  584. end;
  585.  
  586. function TIvPageSetupDialog.Printer(Wnd: HWND): boolean;
  587. begin
  588.   Result :=  assigned(FOnPrinter);
  589.   if Result then
  590.     FOnPrinter(Self, Wnd);
  591. end;
  592.  
  593. function TIvPageSetupDialog.DoPrinter(Wnd: HWND): boolean;
  594. begin
  595.   try
  596.     Result := Printer(Wnd);
  597.   except
  598.     Result := FALSE;
  599.     Application.HandleException(Self);
  600.   end;
  601. end;
  602.  
  603. const
  604.   SHEET_C = 'Multilizer';
  605.  
  606. procedure Register;
  607. begin
  608.   RegisterComponents(SHEET_C, [TIvPageSetupDialog]);
  609. end;
  610.  
  611. end.
  612.